package com.yanqu.road.server.channelserver.cmd.activity.entername;

import com.yanqu.road.entity.activity.entername.EnterNameParam;
import com.yanqu.road.logic.activity.entername.ChannelEnterNameHelper;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.server.channelserver.manager.activity.entername.ChannelEnterNameMgr;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = ChannelProtocol.N_ENTER_NAME_ADD, desc = "活动报名")
public class ChannelEnterNameAddCmd extends ChannelCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        EnterNameProto.ChannelEnterNameAddReqMsg reqMsg = EnterNameProto.ChannelEnterNameAddReqMsg.parseFrom(packet.getBytes());

        EnterNameParam param = ChannelEnterNameHelper.parseFromMsg(reqMsg);

        ret = ChannelEnterNameMgr.enterNameAdd(param);

        if(ret != 0){
            ChannelMessageHelper.sendGamePacket(Protocol.U_ENTER_NAME_ADD,
                    EnterNameProto.EnterNameAddRespMsg.newBuilder().setRet(ret),
                    reqMsg.getUserKey().getChannelId(), reqMsg.getUserKey().getServerId(), packet.getPlayerId());
        }
    }

    @Override
    public void sendData() {

    }
}
